package com.mzkj.wanjulaile.mobile.api.modules.account.service;

import com.google.common.collect.Lists;
import com.mzkj.common.utils.Collections3;
import com.mzkj.wanjulaile.mobile.api.modules.account.constant.Constant;
import com.mzkj.wanjulaile.mobile.api.modules.account.entity.BuyVip;
import com.mzkj.wanjulaile.mobile.api.modules.account.entity.VipCategory;
import com.mzkj.wanjulaile.mobile.api.modules.account.mapper.AccountMapper;
import com.mzkj.wanjulaile.mobile.api.modules.account.mapper.BuyVipMapper;
import com.mzkj.wanjulaile.mobile.api.modules.account.mapper.VipCategoryMapper;
import com.mzkj.wanjulaile.mobile.api.modules.account.mapper.VipSchemeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * VIP总类别Service
 *
 * @author ianly
 * @version 2017-01-04
 */
@Service
@Transactional(readOnly = true)
public class VipCategoryServiceImpl implements VipCategoryService {
    @Autowired
    private VipSchemeMapper vipSchemeDao;
    @Autowired
    private BuyVipMapper buyVipDao;
    @Autowired
    private AccountMapper accountDao;
    @Autowired
    private VipCategoryMapper vipCategoryMapper;

    public VipCategory get(String id) {
        return vipCategoryMapper.get(id);
    }

    /**
     * 微信端根据vip种类获取关联的vip制度信息
     *
     * @param vipCategory
     * @return
     */
    public VipCategory getVipSchemeByCategory(VipCategory vipCategory) {
        return vipCategoryMapper.getVipSchemeByCategory(vipCategory);
    }

    public List<VipCategory> wxFindList(VipCategory vipCategory, String accountId) {
        List<VipCategory> vipCategoryList = vipCategoryMapper.findList(vipCategory);
        // 非新用户不显示体验会员
        List<BuyVip> allList = buyVipDao.findFullVipByAccountId(accountId);
        List<VipCategory> delVipCategoryList = Lists.newArrayList();
        if (!Collections3.isEmpty(allList)) {
            for (int i = 0; i < vipCategoryList.size(); i++) {
                if (vipCategoryList.get(i).getType().equals(Constant.TEMP_STAR_VIP)){
                    delVipCategoryList.add(vipCategoryList.get(i));
                }
            }
        }
        vipCategoryList.removeAll(delVipCategoryList);
        return vipCategoryList;
    }
    public VipCategory getByType(int type) {
        return vipCategoryMapper.getByType(type);
    }
}